<?php

App::import('Vendor', 'phpFlickr', array('file'=> 'phpFlickr/phpFlickr.php'));

class Picture extends AppModel {

	var $name = "Picture";
  
	var $useTable = false;
	
	var $apiKey = 'aea99f77e685360f7671dc5ba31c287b';
	
	var $flickr = null;
	
	function __construct() {
		parent::__construct();
		$this->flickr = new phpFlickr($this->apiKey);
	}
	
	function getUserIdFromEmail($email) {
		return $this->flickr->people_findByEmail($email);
	}
	
	function getError() {
		$e = array($this->flickr->getErrorCode(), $this->flickr->getErrorMsg());
		return ($e[0] !== false) ? $e : false;
	}
	
	function findAll($conditions = array(), $fields = null, $order = null, $limit = null, $page = null, $recursive = -1) {
		$request = $conditions;
		$r_opts = array('order' => 'sort', 'limit' => 'per_page', 'page' => 'page');
		foreach($r_opts as $arg => $r_opt) {
			if (${$arg} !== null) {
				$request[$r_opt] = ${$arg};
			}
		}
		$result = $this->flickr->photos_search($request);
		return $result;
	}
	
	function find($conditions, $fields = null, $order = null, $recursive = -1) {
		$result = $this->findAll($conditions, $fields, $order, 1, 1, $recursive);
		return $result[0];
	}
	
	function getUrl($photo, $size = 'medium') {
		return $this->flickr->buildPhotoUrl($photo, $size);
	}
}

?>